package com.dao;

import com.beans.UserInfo;
import com.jdbc.DBUtil;

public class UserDao {

	//用户登录
	public UserInfo getLoginUser(String userName, String password) {
		return DBUtil.getSingleObj("select * from userInfo where userName=? and password=? ", UserInfo.class, userName,password);
	}

	//用户注册
	public int addUser(UserInfo user) {
		String sql="insert into userInfo (userName,password,phone,note) values ( ?, ?, ?, ? )";
		return DBUtil.update(sql,user.getUserName(), user.getPassword(),  user.getPhone(),  user.getNote()  );
	}

	//根据账号删除用户,本方法只用于用户注册在hdfs上创建用户目录失败时(用到的机率极小)
	public int delUser(String userName) {
		return DBUtil.update("delete form userInfo where userName=?",userName);
	}

	//根据用户名查询用户信息(用来判断用户名是否被用过)
	public UserInfo getUserByName(String userName) {
		return DBUtil.getSingleObj("select * from userInfo where userName=?  limit 1 ", UserInfo.class, userName);
	}

}
